{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "user_rec = [4,4,4]      # 用户给的推荐矩阵 --> 选6个加权平均\n",
    "\n",
    "from base.models.travelSpotLDA import travelSpotLDA\n",
    "places = {}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 构造景点列表\n",
    "p = travelSpotLDA.objects.all() \n",
    "for item in p: \n",
    "    rankList = []\n",
    "    rankList.append(item.score_culture)\n",
    "    rankList.append(item.score_nature)\n",
    "    rankList.append(item.score_food)\n",
    "\n",
    "    places[item.spot.tid] = rankList\n",
    "\n",
    "print(places) #  71519336: [0.7070250957214373, 0.139659626473506, 0.1533152778050565]} ..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "finall = []\n",
    "for place , features in places.items():\n",
    "    finall.append((place,np.dot(user_rec,features)))\n",
    "\n",
    "res = sorted(finall,key=lambda x : x[1],reverse=True)[:5]\n",
    "# 返回tid 排名最符合的列表"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
